<template>
  <div>
    <div class="header">
      <van-image
        round
        width="60"
        height="60"
        fit="cover"
        :src="userInfo.photo"
      />
      <h2 class="name">
        {{ userInfo.name }}
        <br />
        <van-tag color="#fff" text-color="#009afb">{{
          userInfo.birthday
        }}</van-tag>
      </h2>
    </div>
    <div class="nav">
      <van-row>
        <van-col span="8">
          <van-icon name="notes-o" color="#7af" />
          <span>我的作品</span>
        </van-col>
        <van-col span="8"
          ><van-icon name="star-o" color="#f00" />
          <span>我的收藏</span></van-col
        >
        <van-col span="8"
          ><van-icon name="tosend" color="#fa0" />
          <span>阅读历史</span></van-col
        >
      </van-row>
    </div>
    <div>
      <van-cell
        title="编辑资料"
        is-link
        icon="edit"
        @click="$router.push('/edit')"
      />
      <van-cell
        title="小智同学"
        is-link
        icon="after-sale
"
      />
      <van-cell title="系统设置" is-link icon="setting-o" />
      <van-cell title="退出登录" is-link icon="info-o" @click="loginout" />
    </div>
  </div>
</template>

<script>
import { getuserInfo } from './user.js'
import { removeToken } from '../../untils/token.js'
export default {
  name: 'user',
  data () {
    return {
      userInfo: {}
    }
  },
  methods: {
    loginout () {
      this.$dialog
        .confirm({
          title: '提示',
          message: '确定要退出吗'
        })
        .then(() => {
          removeToken()
          this.$router.push('/login')
        })
    }
  },
  created () {
    getuserInfo().then(res => {
      console.log(res)
      this.userInfo = res.data.data
      this.$store.commit('editUserInfo', res.data.data)
    })
  }
}
</script>

<style lang="less">
.header {
  height: 100px;
  background-color: #328ffe;
  display: flex;
  align-items: center;
  padding: 10px, 15px;
  padding-left: 15px;
  .name {
    font-size: 18px;
    margin-left: 15px;
    color: white;
    font-weight: 400;
  }
}
.van-row {
  .van-col {
    margin-top: 10px;
    justify-content: flex-start;
    text-align: center;
    span {
      display: block;
      font-size: 12px;
    }
  }
}
</style>
